import { createRouter, createWebHashHistory } from 'vue-router';

const routes = [
  {
    path: '/',
    component: () => import('@/pages/homePage.vue'),
    children: [
        {
          path: '/',
          component: () => import('@/subPages/homePage.vue'),
        },
        {
          path: '/userCenter',
          component: () => import('@/subPages/homeUserCenter.vue'),
        },
        {
          path: '/searchUniversities',
          component: () => import('@/subPages/searchUniversities.vue'),
        },
        {
          path: '/searchMajors',
          component: () => import('@/subPages/searchMajors.vue'),
        },
        {
          path: '/userFavorites',
          component: () => import('@/subPages/userFavorites.vue'),
        },
        {
          path: '/fillApplication',
          component: () => import('@/subPages/fillApplication.vue'),
        },
        {
          path: '/professionalAdvice',
          component: () => import('@/subPages/professionalAdvice.vue'),
        },
        {
          path: '/qaArea',
          component: () => import('@/subPages/qaArea.vue'),
        },
      ]
  },
  {
    path: '/login',
    component: () => import('@/pages/UserLogin.vue'),
  },
  {
    path: '/teacher',
    component: () => import('@/pages/teacherPage.vue'),
  },
  {
    path: '/background',
    component: () => import('@/pages/backgroundPage.vue'),
    children: [
      {
        path: '/background',
        component: () => import('@/subPages/backgroundHome.vue'),
      },
      {
        path: '/backgroundStudent',
        component: () => import('@/subPages/backgroundStudent.vue'),
      },
      {
        path: '/backgroundUniversity',
        component: () => import('@/subPages/backgroundUniversity.vue'),
      },
      {
        path: '/backgroundMajor',
        component: () => import('@/subPages/backgroundMajor.vue'),
      },
      {
        path: '/backgroundNews',
        component: () => import('@/subPages/backgroundNews.vue'),
      },
      {
        path: '/backgroundCity',
        component: () => import('@/subPages/backgroundCity.vue'),
      },
      {
        path: '/backgroundScoreranking',
        component: () => import('@/subPages/backgroundScoreranking.vue'),
      },
      {
        path: '/backgroundSystem',
        component: () => import('@/subPages/backgroundSystem.vue'),
      },
      {
        path: '/backgroundVip',
        component: () => import('@/subPages/backgroundVip.vue'),
      },
      ]
  },
  
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

// router.beforeEach((to) => {
//   const store = useStore();
//   const role = to.meta.role;
//   store.updatePageName(to);

//   // 未登陆情况下跳转登陆界面
//   if (
//     !store.user.loginState &&
//     to.path !== '/work/login' &&
//     to.path !== '/duty/login' &&
//     to.path !== '/admin/login'
//   ) {
//     // 重定向至登录
//     if (to.meta.system === 'dutyReporting') return { path: '/duty/login' };
//     if (to.meta.system === 'workCooperation') return { path: '/work/login' };
//     if (to.meta.system === 'admin') return { path: '/admin/login' };
//   }

//   // 判断系统是否匹配
//   console.log(to.meta.system, store.system);
//   if (to.meta.system && to.meta.system !== store.system) {
//     if (to.meta.system === 'dutyReporting') return { path: '/duty/login' };
//     if (to.meta.system === 'workCooperation') return { path: '/work/login' };
//     if (to.meta.system === 'admin') return { path: '/admin/login' };
//   }

//   // 判断是否未授权进入
//   if (role !== 'any' && role !== store.user.role && !role.includes(store.user.role)) {
//     if (to.path === '/' && store.system === 'admin') return { path: '/admin/dutyRelationship' };
//     if (to.path === '/' && store.system === 'dutyReporting') return { path: '/duty/workbench' };
//     if (to.path === '/' && store.system === 'workCooperation') return { path: '/work/workbench' };

//     return {
//       path: '/NotPermission',
//     };
//   }

//   if (to.path === '/work') return { path: '/work/workbench' };
//   if (to.path === '/duty') return { path: '/duty/workbench' };
//   if (to.path === '/admin') return { path: '/admin/dutyRelationship' };
// });

export default router;
